home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue60 / Clinic / OutlookU.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-06-27  |  1.3 KB  |  63 lines

  1. unit OutlookU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     procedure Button1Click(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.     { Public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.DFM}
  25.  
  26. uses
  27.   ComObj;
  28.  
  29. procedure SendMail(const Subject, MessageText, MailFromAddress,
  30.   MailToAddress: String; const Attachments: array of String);
  31. var
  32.   Outlook, Mail, Recipient: Variant;
  33.   I: Integer;
  34. const
  35.   olMailItem = 0;
  36. const
  37.   olOriginator = $00000000;
  38.   olTo = $00000001;
  39. begin
  40.   Outlook := CreateOleObject('Outlook.Application');
  41.   Mail := Outlook.CreateItem(olMailItem);
  42.   Recipient := Mail.Recipients.Add(MailToAddress);
  43.   Recipient.Type := olTo;
  44.   Recipient := Mail.Recipients.Add(MailFromAddress);
  45.   Recipient.Type := olOriginator;
  46.   for I := 1 to Mail.Recipients.Count do
  47.     Mail.Recipients[I].Resolve;
  48.   Mail.Subject := Subject;
  49.   Mail.Body := MessageText;
  50.   for I := Low(Attachments) to High(Attachments) do
  51.     Mail.Attachments.Add(Attachments[I]);
  52.   Mail.Save;
  53.   Mail.Send
  54. end;
  55.  
  56. procedure TForm1.Button1Click(Sender: TObject);
  57. begin
  58.   SendMail('Subject', 'Message text', 'clinic@blong.com',
  59.     'chrisf@itecuk.com', ['c:\autoexec.bat'])
  60. end;
  61.  
  62. end.
  63.